<?php
/**
 * Created by <xinxin.deng>.
 * Author: xinxin.deng
 * Date: 2018/9/4 14:23
 */

error_reporting(E_ALL);
set_time_limit(0);
include_once dirname(dirname(dirname(dirname(dirname(__FILE__)))))."/common.php";
\ns_core\m_load::load("ns_model.message.message_explain");
\ns_core\m_load::load("ns_core.m_pinyin");
\ns_core\m_load::load("ns_core.m_config");
\ns_core\m_load::load_old("nn_logic/log_model/nn_log.class.php");
\ns_core\m_load::load_old("nn_logic/video/vod_index.class.php");
\ns_core\m_load::load_old("nn_logic/video/vod_media.class.php");
\ns_core\m_load::load_np("np_http_curl.class.php");

$arr_dir = explode('|', str_replace(array ('/','\\'), '|', __DIR__));
$str_dir = array_pop($arr_dir);
define('DEFAULT_SOURCE_ID', $str_dir);

class message extends \ns_model\message\message_explain
{
    private $arr_picture = null;

    private $arr_map = null;

    private $notify_video_type_map =array(
        1 => 'Series',
        2 => 'Program',
        3 => 'Movie',
    );

    private $notify_video_id_map =array(
        1 => 'mg_asset_id',
        2 => 'mg_part_id',
        3 => 'mg_file_id',
    );

    //一级分类,影片种类
    private $category_map = array (
        '0' => '电影',  //电影
        '1' => '电视剧',  //电视剧
        '2' => '娱乐,综艺',  //综艺
        '3' => '动画',  //动漫
        '4' => '音乐',  //音乐
        '5' => '纪实,纪录片',  //
        '6' => '法治,科教',  //教育
        '7' => '体育',  //体育
        '8' => '生活',  //生活
        '9' => '经济',  //财经
        '10' => '特别节目',//微电影
        '11' => '品牌专区',//品牌专区
        '12' => '广告',  //广告
        '13' => '新闻', //新闻
        '14' => '公开课',
        '15' => '外语及其他语言',
        '16' => '青少年',
        '17' => '播客',
    );
    private $arr_cp_config = array();
    private $str_cp_id = null;
    private $msg_id = null;
    private $str_video_id = '';
    private $str_video_type = '';

    //片源清晰度对应
    private $media_definition = array(
        1 => 'low',//流畅
        2 => 'std',//标清
        3 => 'hd',//高清
        4 => 'sd',//超高清
    );

    //上游跟栏目id对应cms媒资包id
    //新建媒资包必须配置对应
    private $assists_arr = array(
        '8177' => 'OTT-tiyu',//体育//键‘8193’是上游根栏目id，值‘koznakjilupian’是下游cms的媒资包id
        '8179' => 'OTT-jilupian',//纪录片
        '8181' => 'OTT-dianying',//电影
        '8183' => 'OTT-shaoer',//少儿
        '8185' => 'OTT-jiaoyu',//教育
        '8187' => 'OTT-dianshijv',//电视剧
        '8189' => 'OTT-zongyi',//综艺
        '8191' => 'OTT-yugao',//预告
    );

    public function init()
    {

    }

    public function explain($message)
    {
        \ns_core\m_load::load_np("np_xml2array.class.php");
        $this->arr_cp_config = \m_config::_get_cp_info($message['nns_cp_id']);
        $this->str_cp_id = $message['nns_cp_id'];
        $this->msg_id = $message['nns_message_id'];
        $content = $this->get_message_content($message);
        if($content['ret'] !=0 || strlen($content['data_info']) <1)
        {
            $this->create_xml_respond_msg_to_csp(1, "消息GUID[{$message['nns_id']}]获取消息内容失败或者内容为空");
            return $content;
        }
        $str_content = m_config::trim_xml_header($content['data_info']);
        if(!m_config::is_xml($str_content))
        {
            $this->create_xml_respond_msg_to_csp(1, "消息GUID[{$message['nns_id']}]xml内容非xml结构");
            return m_config::return_data(1,"消息GUID[{$message['nns_id']}]xml内容非xml结构");
        }

        //解析下载的XML
        $dom = new DOMDocument('1.0', 'utf-8');
        $dom->loadXML($str_content);
        $xml = $dom->saveXML();
        $xml_arr = np_xml2array::getArrayData($xml);
        if ($xml_arr["ret"] == 0)
        {
            $this->create_xml_respond_msg_to_csp(1, "消息GUID[{$message['nns_id']}]xml解析失败");
            return m_config::return_data(1,"消息GUID[{$message['nns_id']}]xml解析失败");
        }
        $Objects = null;
        // 		$Maps = null;
        foreach ($xml_arr['data']['children'] as $v)
        {
            if (empty($Objects) && $v['name'] == 'Objects')
            {
                $Objects = $v['children'];
            }
            else if (empty($this->arr_map) && $v['name'] == 'Mappings')
            {
                $this->arr_map = $v['children'];
            }
        }

        if(is_array($this->arr_map))
        {
            \m_config::write_message_execute_log("上下线mapping数据为：" . var_export($this->arr_map, true), $this->str_cp_id);
            foreach ($this->arr_map as $map)
            {
                $map_children = isset($map['children']) ? $map['children'] : array();
                $map = $map['attributes'];
                
                //上下线逻辑
                if ($map['ParentType'] == 'Category')
                {
                    //此时是上下线
                    //消息操作指令:1添加2修改3删除,4上线,5下线
                    $action = null;
                    if ($map['Action'] == 'DELETE')
                    {
                        $action = 5;
                    }
                    else
                    {
                        $action = 4;
                    }
                    //注入ID
                    $asset_id = $map['ElementID'];
                    //栏目ID
                    $content = array();
                    $assists_id = '';

                    //媒资包跟栏目对应
                    if (isset($this->assists_arr["{$map['ParentID']}"]) && strlen($this->assists_arr["{$map['ParentID']}"]) > 0)
                    {
                        $map['ParentID'] = $this->assists_arr["{$map['ParentID']}"];
                        $assists_id = $this->assists_arr["{$map['ParentID']}"];
                    }
                    //上下线主媒资名称
                    $ElementName = null;
                    $Sequence = 0;
                    if (is_array($map_children))
                    {
                        foreach ($map_children as $pro)
                        {
                            if ($pro['attributes']['Name'] == 'ElementName')
                            {
                                $ElementName = $pro['content'];
                            }
                            if ($pro['attributes']['Name'] == 'Sequence')
                            {
                                $Sequence = $pro['content'];
                            }
                            //上线时传的根栏目id，也就是对应cms媒资包id
                            if ($pro['attributes']['Name'] == 'AssetsID')
                            {
                                //媒资包跟栏目对应
                                if (isset($this->assists_arr["{$pro['content']}"]) && strlen($this->assists_arr["{$pro['content']}"]) > 0 && $pro['content'] != 0)
                                {
                                    $assists_id = $this->assists_arr["{$pro['content']}"];
                                }
                            }
                        }
                    }
                    $content['category_id'] = $map['ParentID'];
                    $content['cp_id'] = isset($this->str_cp_id) ? $this->str_cp_id : 0;
                    $content['action'] = $action;
                    $content['asset_id'] = isset($assists_id) && strlen($assists_id) > 0 ? $assists_id : 'HskstVod';
                    $content['order'] = $Sequence;
                    \m_config::write_message_execute_log("开始执行上下线：" . var_export($content, true), $this->str_cp_id);
                    $re = $this->line_asset($content, $asset_id);
                    $this->create_xml_respond_msg_to_csp($re['ret'], $re['reason']);
                    if ($re['ret'] != 0 )
                    {
                        return $re;
                    }
                }
            }
        }
        //Series数据数组
        $arr_series = array ();
        //Program数据数组
        $arr_program = array ();
        //Movie数据数组
        $arr_movie = array ();
        //Picture数据数组
        $arr_picture = array ();
        //Channel数据数组
        $arr_channel = array ();

        //直播分集数据数组
        $arr_live_index = array ();

        //直播片源数据数组
        $arr_live_media = array ();

        //schedulerecord节目单数据数组
        $arr_playbill = array ();

        //category栏目数组
        $arr_category = array();

        $arr_cast_role_map = array();
        $arr_cast = array();

        if (!empty($Objects) && is_array($Objects))
        {
            foreach ($Objects as $obj)
            {
                if ($obj['attributes']['ElementType'] == 'Series')
                {
                    $arr_series[]=$this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'Program')
                {
                    $arr_program[]=$this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'Movie')
                {
                    $arr_movie[]=$this->make_key_value_arr($obj);
                }
                //直播频道
                else if ($obj['attributes']['ElementType'] == 'Channel')
                {
                    $arr_channel[]=$this->make_key_value_arr($obj);
                }
                //直播片源
                else if ($obj['attributes']['ElementType'] == 'PhysicalChannel')
                {
                    $arr_live_media[]=$this->make_key_value_arr($obj);
                }
                //直播分集
                else if ($obj['attributes']['ElementType'] == 'PhysicalChannel')
                {
                    $arr_live_index[]=$this->make_key_value_arr($obj);
                }
                //节目单
                else if ($obj['attributes']['ElementType'] == 'ScheduleRecord')
                {
                    $arr_playbill[]=$this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'Picture')
                {
                    $this->arr_picture[]=$this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'Category')
                {
                    $arr_category[]=$this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'CastRoleMap')
                {
                    //类型为castMap的obj
                    $arr_cast_role_map[] = $this->make_key_value_arr($obj);
                }
                else if ($obj['attributes']['ElementType'] == 'Cast')
                {
                    //类型为cat的obj
                    $arr_cast[] = $this->make_key_value_arr($obj);
                }
            }
        }

        $cast_obj = array();
        if(!empty($arr_cast) && is_array($arr_cast))
        {
            foreach ($arr_cast as $cast_value)
            {
                $cast_obj[$cast_value['ContentID']]=$cast_value['key_val_list']['Name'];
            }
        }

        $series_cast_data = array();
        if(!empty($arr_cast_role_map) && is_array($arr_cast_role_map))
        {
            foreach ($arr_cast_role_map as $cast_role_map_value)
            {
                if(!isset($cast_role_map_value['key_val_list']['CastRole']) || strlen($cast_role_map_value['key_val_list']['CastRole']) <1 ||
                    !isset($cast_role_map_value['key_val_list']['CastID']) || strlen($cast_role_map_value['key_val_list']['CastID']) <1 )
                {
                    continue;
                }
                if(!isset($cast_obj[$cast_role_map_value['key_val_list']['CastID']]) || strlen($cast_obj[$cast_role_map_value['key_val_list']['CastID']]) < 1)
                {
                    continue;
                }
                if($cast_role_map_value['key_val_list']['CastRole'] == '导演')
                {
                    $series_cast_data['WriterDisplay'][] = $cast_obj[$cast_role_map_value['key_val_list']['CastID']];
                }
                else
                {
                    $series_cast_data['ActorDisplay'][] = $cast_obj[$cast_role_map_value['key_val_list']['CastID']];
                }
            }
        }

        //主媒资操作   主媒资增删改走以前老逻辑，基本没什么变化
        if (!empty($arr_series))
        {
            $this->str_video_type = 'Series';
            foreach ($arr_series as $val_series)
            {
                $this->str_video_id = $val_series['ContentID'];
                //主媒资删除
                if (strtoupper($val_series['Action']) == 'DELETE')
                {
                    $del_series = array(
                        'base_info'=>array(
                            'nns_asset_import_id'=>$val_series['ContentID'],
                            'nns_import_source'=>isset($val_series['nns_import_source']) ? $val_series['nns_import_source'] : evn::get("project"),
                            'nns_cp_id'=>$message['nns_cp_id'],
                        ),
                    );
                    $result = $this->vod_action('delete', $del_series);
                }
                else
                {
                    //默认一级分类为电影
                    $view_type = 0;
                    $asset_category = (isset($val_series['key_val_list']['Type']) && strlen($val_series['key_val_list']['Type']) >0) ? $val_series['key_val_list']['Type'] : '电影';
                    $do_category = array(
                        'base_info'=>array(
                            'nns_name'=>$asset_category,   //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_import_category_id'=>'', //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_cp_id'=>$message['nns_cp_id'],
                            'nns_import_parent_category_id'=>'',
                            'nns_video_type'=>'0',  //媒资类型  0 点播 | 1 直播
                        ),
                    );
                    $result = $this->category_action('add', $do_category);

                    if($result['ret'] !=0)
                    {
                        $this->create_xml_respond_msg_to_csp($result['ret'], $result['reason']);
                        return $result;
                    }
                    if(!isset($result['data_info']['base_info']['nns_id']) || strlen($result['data_info']['base_info']['nns_id']) <1)
                    {
                        $this->create_xml_respond_msg_to_csp(1, '创建栏目失败');
                        return m_config::return_data(1,'创建栏目失败');
                    }
                    $nns_category_id = $result['data_info']['base_info']['nns_id'];
                    foreach ($this->category_map as $index => $v)
                    {
                        if (stripos($v, $asset_category) !== false)
                        {
                            $view_type = $index;
                            break;
                        }
                    }
                    if($view_type == 0 && isset($val_series['key_val_list']['VolumnCount']) && $val_series['key_val_list']['VolumnCount'] >1)
                    {
                        $view_type = 1;
                    }
                    if((!isset($val_series['key_val_list']['ActorDisplay']) || strlen($val_series['key_val_list']['ActorDisplay']) <1) && isset($series_cast_data['ActorDisplay']) && !empty($series_cast_data['ActorDisplay']) && is_array($series_cast_data['ActorDisplay']))
                    {
                        $val_series['key_val_list']['ActorDisplay'] = implode(',', $series_cast_data['ActorDisplay']);
                    }
                    if((!isset($val_series['key_val_list']['WriterDisplay']) || strlen($val_series['key_val_list']['WriterDisplay']) <1) && isset($series_cast_data['WriterDisplay']) && !empty($series_cast_data['WriterDisplay']) && is_array($series_cast_data['WriterDisplay']))
                    {
                        $val_series['key_val_list']['WriterDisplay'] = implode(',', $series_cast_data['WriterDisplay']);
                    }
                    #TODO
                    $arr_img = $this->handle_picture_v3($val_series['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_series['key_val_list'] = array_merge($val_series['key_val_list'], $arr_img);
                    }
                    $pinyin = m_pinyin::get_pinyin_letter($val_series['key_val_list']['Name']);
                    $add_series = array(
                        'base_info'=>array(
                            'nns_name'=>isset($val_series['key_val_list']['Name']) ? $val_series['key_val_list']['Name'] : '',
                            'nns_view_type'=>$view_type,
                            'nns_org_type'=>'0',
                            'nns_tag'=>'26,27,28,29,30,31,',
                            'nns_director'=>isset($val_series['key_val_list']['WriterDisplay']) ? $val_series['key_val_list']['WriterDisplay'] : '',
                            'nns_actor'=>isset($val_series['key_val_list']['ActorDisplay']) ? $val_series['key_val_list']['ActorDisplay'] : '',
                            'nns_show_time'=>(isset($val_series['key_val_list']['ReleaseYear']) && strlen($val_series['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_series['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_view_len'=>isset($val_series['key_val_list']['Duration']) ? $val_series['key_val_list']['Duration'] : 0,
                            'nns_all_index'=>isset($val_series['key_val_list']['VolumnCount']) ? $val_series['key_val_list']['VolumnCount'] : 1,
                            'nns_new_index'=>isset($val_series['key_val_list']['NewCount']) ? $val_series['key_val_list']['NewCount'] : 0,
                            'nns_area'=>isset($val_series['key_val_list']['OriginalCountry']) ? $val_series['key_val_list']['OriginalCountry'] : '',
                            'nns_image0'=>isset($val_series['key_val_list']['bigpic']) ? $val_series['key_val_list']['bigpic'] : '',
                            'nns_image1'=>isset($val_series['key_val_list']['middlepic']) ? $val_series['key_val_list']['middlepic'] : '',
                            'nns_image2'=>isset($val_series['key_val_list']['smallpic']) ? $val_series['key_val_list']['smallpic'] : '',
                            'nns_image3'=>'',
                            'nns_image4'=>'',
                            'nns_image5'=>'',
                            'nns_summary'=>isset($val_series['key_val_list']['Description']) ? $val_series['key_val_list']['Description'] : '',
                            'nns_remark'=>isset($val_series['key_val_list']['Kind']) ? $val_series['key_val_list']['Kind'] : '',
                            'nns_category_id'=>$nns_category_id,
                            'nns_play_count'=>'0',
                            'nns_score_total'=>'0',
                            'nns_score_count'=>'0',
                            'nns_point'=>isset($val_series['key_val_list']['ViewPoint']) ? $val_series['key_val_list']['ViewPoint'] : '0',
                            'nns_copyright_date'=>(isset($val_series['key_val_list']['ReleaseYear']) && strlen($val_series['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_series['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_asset_import_id'=>$val_series['ContentID'],
                            'nns_pinyin'=>(isset($val_series['key_val_list']['Spell']) && strlen($val_series['key_val_list']['Spell'])>0) ? $val_series['key_val_list']['Spell'] : $pinyin,
                            'nns_pinyin_length'=>(isset($val_series['key_val_list']['Spell']) && strlen($val_series['key_val_list']['Spell'])>0) ? strlen($val_series['key_val_list']['Spell']) : strlen($pinyin),
                            'nns_alias_name'=>isset($val_series['key_val_list']['AliasName']) ? $val_series['key_val_list']['AliasName'] : '',
                            'nns_eng_name'=>isset($val_series['key_val_list']['EnglishName']) ? $val_series['key_val_list']['EnglishName'] : '',
                            'nns_language'=>isset($val_series['key_val_list']['Language']) ? $val_series['key_val_list']['Language'] : '',
                            'nns_text_lang'=>isset($val_series['key_val_list']['Language']) ? $val_series['key_val_list']['Language'] : '',
                            'nns_producer'=>isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_screenwriter'=>isset($val_series['key_val_list']['WriterDisplay']) ? $val_series['key_val_list']['WriterDisplay'] : '',
                            'nns_play_role'=>'',
                            'nns_copyright_range'=>isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_vod_part'=>'',
                            'nns_keyword'=>isset($val_series['key_val_list']['Keywords']) ? $val_series['key_val_list']['Keywords'] : '',
                            'nns_import_source'=>isset($val_series['nns_import_source']) ? $val_series['nns_import_source'] : evn::get("project"),
                            'nns_kind'=>isset($val_series['key_val_list']['Kind']) ? $val_series['key_val_list']['Kind'] : '',
                            'nns_copyright'=>isset($val_series['key_val_list']['ContentProvider']) ? $val_series['key_val_list']['ContentProvider'] : '',
                            'nns_clarity'=>'',
                            'nns_image_v'=>isset($val_series['key_val_list']['verticality_img']) ? $val_series['key_val_list']['verticality_img'] : '',
                            'nns_image_s'=>isset($val_series['key_val_list']['square_img']) ? $val_series['key_val_list']['square_img'] : '',
                            'nns_image_h'=>isset($val_series['key_val_list']['horizontal_img']) ? $val_series['key_val_list']['horizontal_img'] : '',
                            'nns_cp_id'=>$message['nns_cp_id'],
                            'nns_conf_info'=>'',
                            'nns_ext_url'=>'',
                        ), //基本信息（存储于nns_vod表中）
                        'ex_info'=>array(
                            'svc_item_id'=>'',
                            'month_clicks'=>'',
                            'week_clicks'=>'',
                            'base_id'=>'',
                            'asset_path'=>'',
                            'ex_tag'=>'',
                            'full_spell'=>'',
                            'awards'=>'',
                            'year'=>'',
                            'play_time'=>'',
                            'channel'=>'',
                            'first_spell'=>'',
                            'online_identify' => isset($val_series['key_val_list']['online_identify']) ? $val_series['key_val_list']['online_identify'] : '',//自定义上下线规则。
                        ), //扩展信息（存储于nns_vod_ex表中）
                    );
                    //字段待修改4-14
                    $result = $this->vod_action('add', $add_series);
                }

                if($result['ret'] !=0)
                {
                    $this->create_xml_respond_msg_to_csp($result['ret'], $result['reason']);
                    return $result;
                }
            }
        }
        //分集操作   分集删除走以前的老逻辑，分集注册  则组装分集和片源的信息到redis，分集更新则查询redis关联数据
        if(!empty($arr_program))
        {
            $this->str_video_type = 'Program';
            foreach ($arr_program as $val_program)
            {
                $this->str_video_id = $val_program['ContentID'];
                //分集删除
                if (strtoupper($val_program['Action']) == 'DELETE')
                {
                    $del_program = array(
                        'base_info' => array(
                            'nns_import_id' => $val_program['ContentID'],
                            'nns_import_source' => isset($val_program['nns_import_source']) ? $val_program['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->index_action('delete', $del_program);
                }
                else
                {
                    $arr_img = $this->handle_picture_v3($val_program['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_program['key_val_list'] = array_merge($val_program['key_val_list'], $arr_img);
                    }
                    $arr_p_series = $this->get_map_info_v2('Program', $this->arr_map, $val_program['ContentID']);
                    $p_series = array_keys($arr_p_series);
                    //新疆IPTV注入文档标准，分集注入  -->start
                    $bool_is_movie = $val_program['key_val_list']["SeriesFlag"];
                    //只有分集，自动创建主媒资
                    if($bool_is_movie == "0")
                    {
                        $view_type = 0;
                        $asset_category = (isset($val_series['key_val_list']['Type']) && strlen($val_program['key_val_list']['Type']) >0) ? $val_program['key_val_list']['Type'] : '电影';
                        $do_category = array(
                            'base_info'=>array(
                                'nns_name'=>$asset_category,   //栏目名称支持多层目录，多层目录的时候 /分割
                                'nns_import_category_id'=>'', //栏目名称支持多层目录，多层目录的时候 /分割
                                'nns_cp_id'=>$message['nns_cp_id'],
                                'nns_import_parent_category_id'=>'',
                                'nns_video_type'=>'0',  //媒资类型  0 点播 | 1 直播
                            ),
                        );
                        $result = $this->category_action('add', $do_category);

                        if($result['ret'] !=0)
                        {
                            $this->create_xml_respond_msg_to_csp($result['ret'], $result['reason']);
                            return $result;
                        }
                        if(!isset($result['data_info']['base_info']['nns_id']) || strlen($result['data_info']['base_info']['nns_id']) <1)
                        {
                            $this->create_xml_respond_msg_to_csp(1, '创建栏目失败');
                            return m_config::return_data(1,'创建栏目失败');
                        }
                        $nns_category_id = $result['data_info']['base_info']['nns_id'];
                        foreach ($this->category_map as $index => $v)
                        {
                            if (stripos($v, $asset_category) !== false)
                            {
                                $view_type = $index;
                                break;
                            }
                        }
                        if($view_type == 0 && isset($val_program['key_val_list']['VolumnCount']) && $val_program['key_val_list']['VolumnCount'] >1)
                        {
                            $view_type = 1;
                        }
                        $pinyin = m_pinyin::get_pinyin_letter($val_program['key_val_list']['Name']);
                        $add_series = array(
                            'base_info'=>array(
                                'nns_name'=>isset($val_program['key_val_list']['Name']) ? $val_program['key_val_list']['Name'] : '',
                                'nns_view_type'=>$view_type,
                                'nns_org_type'=>'0',
                                'nns_tag'=>'26,27,28,29,30,31,',
                                'nns_director'=>isset($val_program['key_val_list']['WriterDisplay']) ? $val_program['key_val_list']['WriterDisplay'] : '',
                                'nns_actor'=>isset($val_program['key_val_list']['ActorDisplay']) ? $val_program['key_val_list']['ActorDisplay'] : '',
                                'nns_show_time'=>(isset($val_program['key_val_list']['ReleaseYear']) && strlen($val_program['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_program['key_val_list']['ReleaseYear'])) : date("Y"),
                                'nns_view_len'=>isset($val_program['key_val_list']['Duration']) ? $val_program['key_val_list']['Duration'] : 0,
                                'nns_all_index'=>isset($val_program['key_val_list']['VolumnCount']) ? $val_program['key_val_list']['VolumnCount'] : 1,
                                'nns_new_index'=>isset($val_program['key_val_list']['NewCount']) ? $val_program['key_val_list']['NewCount'] : 0,
                                'nns_area'=>isset($val_program['key_val_list']['OriginalCountry']) ? $val_program['key_val_list']['OriginalCountry'] : '',
                                'nns_image0'=>isset($val_program['key_val_list']['bigpic']) ? $val_program['key_val_list']['bigpic'] : '',
                                'nns_image1'=>isset($val_program['key_val_list']['middlepic']) ? $val_program['key_val_list']['middlepic'] : '',
                                'nns_image2'=>isset($val_program['key_val_list']['smallpic']) ? $val_program['key_val_list']['smallpic'] : '',
                                'nns_image3'=>'',
                                'nns_image4'=>'',
                                'nns_image5'=>'',
                                'nns_summary'=>isset($val_program['key_val_list']['Description']) ? $val_program['key_val_list']['Description'] : '',
                                'nns_remark'=>isset($val_program['key_val_list']['Kind']) ? $val_program['key_val_list']['Kind'] : '',
                                'nns_category_id'=>$nns_category_id,
                                'nns_play_count'=>'0',
                                'nns_score_total'=>'0',
                                'nns_score_count'=>'0',
                                'nns_point'=>isset($val_program['key_val_list']['ViewPoint']) ? $val_program['key_val_list']['ViewPoint'] : '0',
                                'nns_copyright_date'=>(isset($val_program['key_val_list']['ReleaseYear']) && strlen($val_program['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_program['key_val_list']['ReleaseYear'])) : date("Y"),
                                'nns_asset_import_id'=>$val_program['ContentID'],
                                'nns_pinyin'=>(isset($val_program['key_val_list']['Spell']) && strlen($val_program['key_val_list']['Spell'])>0) ? $val_program['key_val_list']['Spell'] : $pinyin,
                                'nns_pinyin_length'=>(isset($val_program['key_val_list']['Spell']) && strlen($val_program['key_val_list']['Spell'])>0) ? strlen($val_program['key_val_list']['Spell']) : strlen($pinyin),
                                'nns_alias_name'=>isset($val_program['key_val_list']['AliasName']) ? $val_program['key_val_list']['AliasName'] : '',
                                'nns_eng_name'=>isset($val_program['key_val_list']['EnglishName']) ? $val_program['key_val_list']['EnglishName'] : '',
                                'nns_language'=>isset($val_program['key_val_list']['Language']) ? $val_program['key_val_list']['Language'] : '',
                                'nns_text_lang'=>isset($val_program['key_val_list']['Language']) ? $val_program['key_val_list']['Language'] : '',
                                'nns_producer'=>isset($val_program['key_val_list']['ContentProvider']) ? $val_program['key_val_list']['ContentProvider'] : '',
                                'nns_screenwriter'=>isset($val_program['key_val_list']['WriterDisplay']) ? $val_program['key_val_list']['WriterDisplay'] : '',
                                'nns_play_role'=>'',
                                'nns_copyright_range'=>isset($val_program['key_val_list']['ContentProvider']) ? $val_program['key_val_list']['ContentProvider'] : '',
                                'nns_vod_part'=>'',
                                'nns_keyword'=>isset($val_program['key_val_list']['Keywords']) ? $val_program['key_val_list']['Keywords'] : '',
                                'nns_import_source'=>isset($val_program['nns_import_source']) ? $val_program['nns_import_source'] : evn::get("project"),
                                'nns_kind'=>isset($val_program['key_val_list']['Tags']) ? $val_program['key_val_list']['Tags'] : '',
                                'nns_copyright'=>isset($val_program['key_val_list']['ContentProvider']) ? $val_program['key_val_list']['ContentProvider'] : '',
                                'nns_clarity'=>'',
                                'nns_image_v'=>isset($val_program['key_val_list']['verticality_img']) ? $val_program['key_val_list']['verticality_img'] : '',
                                'nns_image_s'=>isset($val_program['key_val_list']['square_img']) ? $val_program['key_val_list']['square_img'] : '',
                                'nns_image_h'=>isset($val_program['key_val_list']['horizontal_img']) ? $val_program['key_val_list']['horizontal_img'] : '',
                                'nns_cp_id'=>$message['nns_cp_id'],
                                'nns_conf_info'=>'',
                                'nns_ext_url'=>'',
                            ), //基本信息（存储于nns_vod表中）
                            'ex_info'=>array(
                                'svc_item_id'=>'',
                                'month_clicks'=>'',
                                'week_clicks'=>'',
                                'base_id'=>'',
                                'asset_path'=>'',
                                'ex_tag'=>'',
                                'full_spell'=>'',
                                'awards'=>'',
                                'year'=>'',
                                'play_time'=>'',
                                'channel'=>'',
                                'first_spell'=>'',
                                'online_identify' => isset($val_program['key_val_list']['online_identify']) ? $val_program['key_val_list']['online_identify'] : '',//自定义上下线规则。
                            ), //扩展信息（存储于nns_vod_ex表中）
                        );
                        $video_result = $this->vod_action('add', $add_series);
                        if($video_result['ret'] != 0)
                        {
                            return $video_result;
                        }
                        $p_series[0] = $val_program['ContentID'];
                    }
                    //新疆IPTV注入文档标准，分集注入  -->end

                    //分集不存在集数字段
                    if (!isset($val_program['key_val_list']['Sequence']) || !strlen($val_program['key_val_list']['Sequence']) > 0)
                    {
                        $val_program['key_val_list']['Sequence'] = isset($arr_p_series[$p_series[0]]['key_val_list']['Sequence']) ? $arr_p_series[$p_series[0]]['key_val_list']['Sequence'] - 1 : 0;
                    }
                    $res = nl_asset_incidence_relation::query_asset_relation(m_config::get_dc(), 'video', $p_series[0], $message['nns_cp_id'], 0);
                    if (!is_array($res['data_info']))
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, '主媒资在平台不存在');
                        $res['ret'] = 7;
                        $res['reason'] = "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],主媒资在平台不存在.原因" . $res['reason'];
                        return $res;
                    }

                    $add_index = array(
                        'base_info' => array(
                            'nns_name' => isset($val_program['key_val_list']['Name']) ? $val_program['key_val_list']['Name'] : '',
                            'nns_index' => $val_program['key_val_list']['Sequence'],
                            'nns_time_len' => '',
                            'nns_summary' => isset($val_program['key_val_list']['Description']) ? $val_program['key_val_list']['Description'] : '',
                            'nns_image' => isset($val_program['key_val_list']['Picture']) ? $val_program['key_val_list']['Picture'] : '',
                            'nns_play_count' => 0,
                            'nns_score_total' => 0,
                            'nns_score_count' => 0,
                            'nns_video_import_id' => $res['data_info'][0]['nns_asset_import_id'],
                            'nns_import_id' => $val_program['ContentID'],
                            'nns_import_source' => isset($val_program['nns_import_source']) ? $val_program['nns_import_source'] : evn::get("project"),
                            'nns_director' => isset($val_program['key_val_list']['WriterDisplay']) ? $val_program['key_val_list']['WriterDisplay'] : '',
                            'nns_actor' => isset($val_program['key_val_list']['ActorDisplay']) ? $val_program['key_val_list']['ActorDisplay'] : '',
                            'nns_release_time' => (isset($val_program['key_val_list']['ReleaseYear']) && strlen($val_program['key_val_list']['ReleaseYear']) > 0) ? date("Y-m-d", strtotime($val_program['key_val_list']['ReleaseYear'])) : date("Y-m-d"),
                            'nns_update_time' => date("Y-m-d"),
                            'nns_watch_focus' => '',
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_conf_info' => '',
                            'nns_ext_url' => '',
                        ),
                        'ex_info' => array(
                            'isintact' => '',
                            'subordinate_name' => '',
                            'initials' => '',
                            'publisher' => '',
                            'first_spell' => '',
                            'caption_language' => '',
                            'language' => isset($val_program['key_val_list']['Language']) ? $val_program['key_val_list']['Language'] : '',
                            'region' => '',
                            'adaptor' => '',
                            'sreach_key' => '',
                            'event_tag' => '',
                            'year' => '',
                            'sort_name' => '',
                        ),
                    );

                    //分集注入
                    $re = $this->index_action('add', $add_index);
                }

                if($re['ret'] != 0)
                {
                    $re['ret'] = 1;
                    $this->create_xml_respond_msg_to_csp($re['ret'], $re['reason']);
                    return $re;
                }
            }
        }
        //片源操作
        if(!empty($arr_movie))
        {
            $this->str_video_type = 'Movie';
            foreach ($arr_movie as $val_movie)
            {
                $this->str_video_id = $val_movie['ContentID'];
                //片源删除
                if (strtoupper($val_movie['Action']) == 'DELETE')
                {

                    $del_movie = array(
                        'base_info' => array(
                            'nns_content_id' => $val_movie['ContentID'],
                            'nns_import_source' => isset($val_movie['nns_import_source']) ? $val_movie['nns_import_source'] : evn::get("project"),
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->media_action('delete', $del_movie);
                } //片源修改
                else
                {
                    $arr_p_program = $this->get_map_info_v2('Movie', $this->arr_map, $val_movie['ContentID']);
                    \m_config::write_message_execute_log('获得的数组为：' . var_export($arr_p_program,true), 'zhongguangchuanbo');
                    $arr_p_program = array_keys($arr_p_program);
                    \m_config::write_message_execute_log('获得的数组为：' . var_export($arr_p_program,true), 'zhongguangchuanbo');
                    $index_info = nl_asset_incidence_relation::query_asset_relation(m_config::get_dc(), 'index', $arr_p_program[0], $message['nns_cp_id'], 1);

                    if (!is_array($index_info['data_info']))
                    {
                        $this->create_xml_respond_msg_to_csp(NS_CDS_FAIL, '对应分集在平台不存在');
                        //返回分集未注入
                        $res['ret'] = 7;
                        $res['reason'] = "消息接收成功,注入失败,消息ID[{$message['nns_message_id']}],对应分集在平台不存在,原因" . $index_info['reason'];
                        return $res;
                    }

                    $index_import_id = $arr_p_program[0];
                    $vod_import_id = $index_info['data_info'][0]['nns_asset_import_id'];

                    //片源参数
                    $add_media = array(
                        'base_info' => array(
                            'nns_name' => isset($val_movie['key_val_list']['Name']) ? $val_movie['key_val_list']['Name'] : '',
                            'nns_type' => 1,
                            'nns_url' => isset($val_movie['key_val_list']['FileURL']) ? $val_movie['key_val_list']['FileURL'] : '',
                            'nns_tag' => '26,27,28,29,30,31,',
                            'nns_mode' => isset($this->media_definition[$val_movie['key_val_list']['VideoProfile']]) ? $this->media_definition[$val_movie['key_val_list']['VideoProfile']] : '',
                            'nns_kbps' => isset($val_movie['key_val_list']['BitRateType']) ? $val_movie['key_val_list']['BitRateType'] : '',
                            'nns_content_id ' => $val_movie['ContentID'],
                            'nns_content_state' => 0,
                            'nns_filetype' => isset($val_movie['key_val_list']['FileType']) ? $val_movie['key_val_list']['FileType'] : 'ts',
                            'nns_play_count' => '0',
                            'nns_score_total' => '0',
                            'nns_score_count' => '0',
                            'nns_video_import_id' => $vod_import_id,
                            'nns_index_import_id' => $index_import_id,
                            'nns_import_id' => $val_movie['ContentID'],
                            'nns_import_source' => isset($val_movie['nns_import_source']) ? $val_movie['nns_import_source'] : evn::get("project"),
                            'nns_dimensions' => isset($val_movie['key_val_list']['Dimensions']) ? $val_movie['key_val_list']['Dimensions'] : '2D',
                            'nns_ext_url' => '',
                            'nns_file_size' => isset($val_movie['key_val_list']['FileSize']) ? $val_movie['key_val_list']['FileSize'] : 0,
                            'nns_file_time_len' => isset($val_movie['key_val_list']['TimeLen']) ? $val_movie['key_val_list']['TimeLen'] : 0,
                            'nns_file_frame_rate' => isset($val_movie['key_val_list']['FrameRate']) ? $val_movie['key_val_list']['FrameRate'] : 0,
                            'nns_file_resolution' => isset($val_movie['key_val_list']['Resolution']) ? $val_movie['key_val_list']['Resolution'] : 0,
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_ext_info' => '',
                            'nns_drm_enabled' => isset($val_movie['key_val_list']['DrmEnabled']) ? $val_movie['key_val_list']['DrmEnabled'] : 0,
                            'nns_drm_encrypt_solution' => isset($val_movie['key_val_list']['DrmEncryptSolution']) ? $val_movie['key_val_list']['DrmEncryptSolution'] : '',
                            'nns_drm_ext_info' => '',
                            'nns_domain' => isset($val_movie['key_val_list']['Domain']) ? $val_movie['key_val_list']['Domain'] : 0,
                            'nns_media_type' => isset($val_movie['key_val_list']['VideoType']) ? $val_movie['key_val_list']['VideoType'] : 1,
                            'nns_original_live_id' => '',
                            'nns_start_time' => '',
                            'nns_media_service' => isset($val_movie['key_val_list']['ServiceType']) ? $val_movie['key_val_list']['ServiceType'] : 'HTTP',
                            'nns_conf_info' => '',
                            'nns_encode_flag' => isset($val_movie['key_val_list']['EncodeFlag']) ? $val_movie['key_val_list']['EncodeFlag'] : 0,
                            'nns_live_to_media' => isset($val_movie['key_val_list']['EncodeType']) ? $val_movie['key_val_list']['EncodeType'] : '',
                            'nns_media_service_type' => '',
                        ),
                        'ex_info' => array(
                            'file_hash' => '',
                            'file_width' => '',
                            'file_height' => '',
                            'file_scale' => '',
                            'file_coding' => '',
                        ),
                    );

                    $re = $this->media_action('add', $add_media);
                }
                if($re['ret'] != 0)
                {
                    $re['ret'] = 1;
                    $this->create_xml_respond_msg_to_csp($re['ret'], $re['reason']);
                    return $re;
                }
            }
        }

        //直播频道操作  直播频道的增删改和主媒资的相同
        if(!empty($arr_channel))
        {
            //循环频道，对每个频道进行处理
            foreach($arr_channel as $val_channel)
            {
                //频道删除操作
                if(strtoupper($val_channel['Action']) == 'DELETE')
                {
                    $del_channel = array(
                        'base_info'=>array(
                            'nns_import_id' => $val_channel['ContentID'],
                            'nns_import_source' => $val_channel['nns_import_source'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->live_action('delete', $del_channel);
                }
                //直播频道更新或者注入
                else
                {
                    //默认一级分类为
                    $view_type = 1;
                    if ($message['nns_cp_id'] == 'JSCN')
                    {
                        $val_channel['key_val_list']['CategoryName'] = (isset($val_channel['key_val_list']['PgmCategory']) && strlen($val_channel['key_val_list']['PgmCategory']) >0) ? $val_channel['key_val_list']['PgmCategory'] : '卫士频道';
                    }
                    $asset_category = (isset($val_channel['key_val_list']['CategoryName']) && strlen($val_channel['key_val_list']['CategoryName']) >0) ? $val_channel['key_val_list']['CategoryName'] : '卫士频道';
                    $category_import_id = (isset($val_channel['key_val_list']['CategoryID']) && strlen($val_channel['key_val_list']['CategoryID']) >0) ? $val_channel['key_val_list']['CategoryID'] : '';

                    $do_category = array(
                        'base_info'=>array(
                            'nns_name' => $asset_category,   //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_import_category_id' => $category_import_id, //栏目名称支持多层目录，多层目录的时候 /分割
                            'nns_cp_id' => $message['nns_cp_id'],
                            'nns_import_parent_category_id' => '',
                            'nns_video_type' => '1',  //媒资类型  0 点播 | 1 直播
                        ),
                    );
                    $result = $this->category_action('add', $do_category);
                    if($result['ret'] !=0)
                    {
                        return $result;
                    }
                    if(!isset($result['data_info']['base_info']['nns_id']) || strlen($result['data_info']['base_info']['nns_id']) <1)
                    {
                        return m_config::return_data(1,'创建栏目失败');
                    }
                    $nns_category_id = $result['data_info']['base_info']['nns_id'];
                    //foreach ($this->category_map as $index => $v)
                    //{
                    //    if (stripos($v, $asset_category) !== false)
                    //    {
                    //        $view_type = $index;
                    //        break;
                    //    }
                    //}
                    //if($view_type == 1 && isset($val_channel['key_val_list']['VolumnCount']) && $val_channel['key_val_list']['VolumnCount'] >1)
                    //{
                    //    $view_type = 1;
                    //}
                    #TODO
                    $arr_img = $this->handle_picture_v3($val_channel['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_series['key_val_list'] = array_merge($val_channel['key_val_list'], $arr_img);
                    }
                    $pinyin = m_pinyin::get_pinyin_letter($val_channel['key_val_list']['Name']);

                    $ext_info = array();
                    //扩展表存放的扩展字段--频道号
                    if (!isset($val_channel['key_val_list']['ChannelNumber']) || strlen($val_channel['key_val_list']['ChannelNumber']))
                    {
                        $ext_info[] = array(
                            'nns_key' => 'live_pindao_order',
                            'nns_value' => $val_channel['key_val_list']['ChannelNumber'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        );
                    }
                    $add_channel = array(
                        'base_info' => array(
                            'nns_name'=>isset($val_channel['key_val_list']['Name']) ? $val_channel['key_val_list']['Name'] : '',
                            'nns_view_type'=>$view_type,
                            'nns_org_type'=>'0',
                            'nns_tag'=>'26,',
                            'nns_director'=>isset($val_channel['key_val_list']['WriterDisplay']) ? $val_channel['key_val_list']['WriterDisplay'] : '',
                            'nns_actor'=>isset($val_channel['key_val_list']['ActorDisplay']) ? $val_channel['key_val_list']['ActorDisplay'] : '',
                            'nns_show_time'=>(isset($val_channel['key_val_list']['ReleaseYear']) && strlen($val_channel['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_channel['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_view_len'=>isset($val_channel['key_val_list']['Duration']) ? $val_channel['key_val_list']['Duration'] : 0,
                            'nns_all_index'=>isset($val_channel['key_val_list']['VolumnCount']) ? $val_channel['key_val_list']['VolumnCount'] : 1,
                            'nns_new_index'=>isset($val_channel['key_val_list']['NewCount']) ? $val_channel['key_val_list']['NewCount'] : 0,
                            'nns_area'=>isset($val_channel['key_val_list']['Country']) ? $val_channel['key_val_list']['Country'] : '',
                            'nns_image0'=>isset($val_channel['key_val_list']['bigpic']) ? $val_channel['key_val_list']['bigpic'] : '',
                            'nns_image1'=>isset($val_channel['key_val_list']['middlepic']) ? $val_channel['key_val_list']['middlepic'] : '',
                            'nns_image2'=>isset($val_channel['key_val_list']['smallpic']) ? $val_channel['key_val_list']['smallpic'] : '',
                            'nns_image3'=>'',
                            'nns_image4'=>'',
                            'nns_image5'=>'',
                            'nns_summary'=>isset($val_channel['key_val_list']['Description']) ? $val_channel['key_val_list']['Description'] : '',
                            'nns_remark'=>isset($val_channel['key_val_list']['Kind']) ? $val_channel['key_val_list']['Kind'] : '',
                            'nns_category_id'=>$nns_category_id,
                            'nns_play_count'=>'0',
                            'nns_score'=>'0',
                            'nns_score_count'=>'0',
                            'nns_point'=>isset($val_channel['key_val_list']['ViewPoint']) ? $val_channel['key_val_list']['ViewPoint'] : '0',
                            'nns_copyright_date'=>(isset($val_channel['key_val_list']['ReleaseYear']) && strlen($val_channel['key_val_list']['ReleaseYear']) >0) ? date("Y",strtotime($val_channel['key_val_list']['ReleaseYear'])) : date("Y"),
                            'nns_import_id'=>$val_channel['ContentID'],
                            'nns_pinyin'=>(isset($val_channel['key_val_list']['Spell']) && strlen($val_channel['key_val_list']['Spell'])>0) ? $val_channel['key_val_list']['Spell'] : $pinyin,
                            'nns_pinyin_length'=>(isset($val_channel['key_val_list']['Spell']) && strlen($val_channel['key_val_list']['Spell'])>0) ? strlen($val_channel['key_val_list']['Spell']) : strlen($pinyin),
                            'nns_alias_name'=>isset($val_channel['key_val_list']['CallSign']) ? $val_channel['key_val_list']['CallSign'] : '',
                            'nns_eng_name'=>isset($val_channel['key_val_list']['EnglishName']) ? $val_channel['key_val_list']['EnglishName'] : '',
                            'nns_language'=>isset($val_channel['key_val_list']['Language']) ? $val_channel['key_val_list']['Language'] : '',
                            'nns_producer'=>isset($val_channel['key_val_list']['ContentProvider']) ? $val_channel['key_val_list']['ContentProvider'] : '',
                            'nns_import_source'=>isset($val_channel['nns_import_source']) ? $val_channel['nns_import_source'] : evn::get("project"),
                            'nns_image_v'=>isset($val_channel['key_val_list']['verticality_img']) ? $val_channel['key_val_list']['verticality_img'] : '',
                            'nns_image_s'=>isset($val_channel['key_val_list']['square_img']) ? $val_channel['key_val_list']['square_img'] : '',
                            'nns_image_h'=>isset($val_channel['key_val_list']['horizontal_img']) ? $val_channel['key_val_list']['horizontal_img'] : '',
                            'nns_image_t'=>'',
                            'nns_cp_id'=>$message['nns_cp_id'],
                            'nns_ext_info'=>'',
                        ), //基本信息（存储于nns_live表中）
                        'ex_info' => $ext_info,//扩展信息（存储于nns_live_ex表中）
                        'hide_info' => array(
                            'nns_id' => np_guid_rand(),
                            'nns_state' => isset($val_channel['key_val_list']['State']) ? $val_channel['key_val_list']['State'] : 1,
                            'nns_deleted' => 0,
                            'nns_check' => isset($val_channel['key_val_list']['Check']) ? $val_channel['key_val_list']['Check'] : 1,
                        )
                    );
                    //字段待修改4-14
                    $result = $this->live_action('add', $add_channel);
                }
                if($result['ret'] != 0)
                {
                    break;
                }
            }
        }

        //直播频道片源
        if(!empty($arr_live_media))
        {
            foreach($arr_live_media as $val_live_media)
            {
                //删除
                if(strtoupper($val_live_media['Action']) == 'DELETE')
                {
                    $del_live_media = array(
                        'base_info'=>array(
                            'nns_content_id' => $val_live_media['ContentID'],
                            'nns_import_source' => $val_live_media['nns_import_source'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $re = $this->live_media_action('delete', $del_live_media);
                }
                //注入和修改
                else
                {
                    $arr_p_channel = $this->get_map_info_v2('PhysicalChannel', $this->arr_map, $val_live_media['ContentID']);
                    $arr_p_channel = array_keys($arr_p_channel);
                    $sql = "select * from nns_live where `nns_import_id` = '{$arr_p_channel[0]}'";
                    $res_channel = nl_query_by_db($sql,$this->import->dc->db());
                    if (!is_array($res_channel))
                    {
                        //返回频道未注入
                        return $re['ret'] = 10;
                    }

                    // 仿照分集
                    $str_index_id = np_guid_rand();
                    $add_live_index =array(
                        'base_info' => array(
                            'nns_name'=> isset($val_live_media['key_val_list']['Name']) ? $val_live_media['key_val_list']['Name'] : '',
                            'nns_index' => 0,
                            'nns_time_len' => 3600,
                            'nns_summary' => '',
                            'nns_image' => '',
                            'nns_play_count' => 0,
                            'nns_score' => 0,
                            'nns_score_count' => 0,
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                        'hide_info' => array(
                            'nns_id' => $str_index_id,
                            'nns_live_id' => $res_channel[0]['nns_id'],
                        )
                    );
                    $sql="select * from nns_live_index where nns_live_id = '{$res_channel[0]['nns_id']}' and nns_cp_id='".$this->cp_id."' limit 1";
                    $result_exist = nl_query_by_db($sql, $this->import->dc->db());
                    if(!is_array($result_exist) || empty($result_exist) || !isset($result_exist[0]) || !is_array($result_exist[0]) || empty($result_exist[0]))
                    {
                        $re = $this->live_index_action('add', $add_live_index);
                        if ($re != 0)
                        {
                            $re['ret'] = 1;
                        }
                        return $re;
                    }
                    else
                    {
                        $str_index_id = $result_exist[0]['nns_id'];
                    }

                    //直播片源参数
                    $add_live_media = array(
                        'base_info' => array(
                            'nns_name'=> isset($val_live_media['key_val_list']['Name']) ? $val_live_media['key_val_list']['Name'] : '',
                            'nns_type'=> 1,
                            'nns_url' => isset($val_live_media['key_val_list']['Url']) ? $val_live_media['key_val_list']['Url'] : '',
                            'nns_tag' => '26,',
                            'nns_mode' => isset($val_live_media['key_val_list']['Mode']) ? $val_live_media['key_val_list']['Mode'] : '',
                            'nns_kbps' => isset($val_live_media['key_val_list']['UnicastUrl']) ? $val_live_media['key_val_list']['UnicastUrl'] : '',
                            'nns_content_id '=> $val_live_media['ContentID'],
                            'nns_content_state' => 0,
                            'nns_filetype' => isset($val_live_media['key_val_list']['FileType']) ? $val_live_media['key_val_list']['FileType'] : 'ts',
                            'nns_play_count' => '0',
                            'nns_score_total' => '0',
                            'nns_score_count' => '0',
                            'nns_media_cps'=> isset($val_live_media['key_val_list']['MediaCPS']) ? $val_live_media['key_val_list']['MediaCPS'] : 'LIVE',
                            'nns_cp_id' => isset($val_live_media['key_val_list']['CPContentID']) ? $val_live_media['key_val_list']['CPContentID'] : $message['nns_cp_id'],
                            'nns_cast_type' => isset($val_live_media['key_val_list']['CastType']) ? $val_live_media['key_val_list']['CastType'] : 0,
                            'nns_message_id' => $message['nns_id'],
                            'nns_timeshift_status' => isset($val_live_media['key_val_list']['TimeShiftStatus']) ? $val_live_media['key_val_list']['TimeShiftStatus'] : 0,
                            'nns_timeshift_delay' => isset($val_live_media['key_val_list']['TimeShiftDelay']) ? $val_live_media['key_val_list']['TimeShiftDelay'] : '',
                            'nns_storage_status' => isset($val_live_media['key_val_list']['StorageStatus']) ? $val_live_media['key_val_list']['StorageStatus'] : 0,
                            'nns_storage_delay' => isset($val_live_media['key_val_list']['StorageDelay']) ? $val_live_media['key_val_list']['StorageDelay'] : '',
                            'nns_drm_enabled' => isset($val_live_media['key_val_list']['DrmEnabled']) ? $val_live_media['key_val_list']['DrmEnabled'] : 0,
                            'nns_drm_encrypt_solution' => isset($val_live_media['key_val_list']['DrmEncryptSolution']) ? $val_live_media['key_val_list']['DrmEncryptSolution'] : '',
                            'nns_drm_ext_info' => isset($val_live_media['key_val_list']['DrmEncryptExt']) ? $val_live_media['key_val_list']['DrmEncryptExt'] : '',
                            'nns_import_source' => isset($val_live_media['nns_import_source']) ? $val_live_media['nns_import_source'] : evn::get("project"),
                            'nns_domain' => isset($val_live_media['key_val_list']['MultiCastPort']) ? $val_live_media['key_val_list']['MultiCastPort'] : '',
                            'nns_media_service' => isset($val_live_media['key_val_list']['MediaService']) ? $val_live_media['key_val_list']['MediaService'] : 'MSP',
                            'nns_ext_url' => '',
                        ), //基本信息（存储于nns_live表中）
                        'hide_info' => array(
                            'nns_id' => np_guid_rand(),
                            'nns_state' => isset($val_live_media['key_val_list']['State']) ? $val_live_media['key_val_list']['State'] : 1,
                            'nns_deleted' => 0,
                            'nns_check' => isset($val_live_media['key_val_list']['Check']) ? $val_live_media['key_val_list']['Check'] : 1,'nns_original_id' => isset($val_channel['key_val_list']['OriginalId']) ? $val_channel['key_val_list']['OriginalId'] : '',
                            'nns_live_id' => $str_index_id,
                        ),
                    );

                    $re = $this->live_media_action('add', $add_live_media);
                    if($re['ret'] !=0)
                    {
                        $re['ret'] = 1;
                    }
                    return $re;
                }
            }
        }

        //节目单注入
        if (!empty($arr_playbill))
        {
            //循环节目单，对每个节目单进行处理
            foreach($arr_playbill as $val_playbill)
            {
                //频道删除操作
                if(strtoupper($val_playbill['Action']) == 'DELETE')
                {
                    $del_playbill = array(
                        'base_info'=>array(
                            'nns_playbill_import_id' => $val_playbill['ContentID'],
                            'nns_import_source' => $val_playbill['nns_import_source'],
                            'nns_cp_id' => $message['nns_cp_id'],
                        ),
                    );
                    $result = $this->playbill_item_action('delete', $del_playbill);
                }
                //节目单更新或者注入
                else
                {
                    #TODO
                    $arr_img = $this->handle_picture_v3($val_playbill['ContentID']);
                    if (!empty($arr_img) && is_array($arr_img))
                    {
                        $val_series['key_val_list'] = array_merge($val_playbill['key_val_list'], $arr_img);
                    }
                    $pinyin = m_pinyin::get_pinyin_letter($val_playbill['key_val_list']['Name']);

                    //开始时间
                    $start_date = isset($val_playbill['key_val_list']['StartDate']) ? $val_playbill['key_val_list']['StartTime'] : date('Ymd');
                    $start_time = isset($val_playbill['key_val_list']['StartTime']) ? $val_playbill['key_val_list']['StartTime'] : date('His');
                    $begin_time = $start_date . " " . $start_time;
                    $begin_time = date('Y-m-d H:i:s', strtotime($begin_time));

                    $time_len = isset($val_playbill['key_val_list']['Duration']) ? $val_playbill['key_val_list']['Duration'] : 0;

                    $end_time = isset($val_playbill['key_val_list']['EndTime']) ? $val_playbill['key_val_list']['EndTime'] : (int)$start_time + (int)$time_len;
                    $end_time = $start_date . " " . $end_time;
                    $end_time = date('Y-m-d H:i:s', strtotime($end_time));

                    $add_playbill = array(
                        'base_info' => array(
                            'nns_name'=>isset($val_playbill['key_val_list']['Name']) ? $val_playbill['key_val_list']['Name'] : '',
                            'nns_view_type'=> 1,
                            'nns_begin_time' => $begin_time,
                            'nns_end_time' => $end_time,
                            'nns_time_len'=>isset($val_playbill['key_val_list']['Duration']) ? $val_playbill['key_val_list']['Duration'] : 0,
                            'nns_live_id' => '',
                            'nns_summary'=>isset($val_playbill['key_val_list']['Description']) ? $val_playbill['key_val_list']['Description'] : '',
                            'nns_image0'=>isset($val_playbill['key_val_list']['bigpic']) ? $val_playbill['key_val_list']['bigpic'] : '',
                            'nns_image1'=>isset($val_playbill['key_val_list']['middlepic']) ? $val_playbill['key_val_list']['middlepic'] : '',
                            'nns_image2'=>isset($val_playbill['key_val_list']['smallpic']) ? $val_playbill['key_val_list']['smallpic'] : '',
                            'nns_image3'=>'',
                            'nns_image4'=>'',
                            'nns_image5'=>'',
                            'nns_pinyin'=>(isset($val_playbill['key_val_list']['Spell']) && strlen($val_playbill['key_val_list']['Spell'])>0) ? $val_playbill['key_val_list']['Spell'] : $pinyin,
                            'nns_pinyin_length'=>(isset($val_playbill['key_val_list']['Spell']) && strlen($val_playbill['key_val_list']['Spell'])>0) ? strlen($val_playbill['key_val_list']['Spell']) : strlen($pinyin),
                            'nns_eng_name'=>isset($val_playbill['key_val_list']['EnglishName']) ? $val_playbill['key_val_list']['EnglishName'] : '',
                            'nns_keyword'=>isset($val_playbill['key_val_list']['Keyword']) ? $val_playbill['key_val_list']['Keyword'] : '',
                            'nns_kind'=>isset($val_playbill['key_val_list']['Kind']) ? $val_playbill['key_val_list']['Kind'] : '',
                            'nns_actor'=>isset($val_playbill['key_val_list']['ActorDisplay']) ? $val_playbill['key_val_list']['ActorDisplay'] : '',
                            'nns_director'=>isset($val_playbill['key_val_list']['WriterDisplay']) ? $val_playbill['key_val_list']['WriterDisplay'] : '',
                            'nns_live_media_id' => isset($val_playbill['PhysicalChannelID']) ? $val_playbill['PhysicalChannelID'] : '',
                            'nns_playbill_import_id'=>$val_playbill['ContentID'],
                            'nns_domain'=>isset($val_playbill['key_val_list']['Domain']) ? $val_playbill['key_val_list']['Domain'] : '',
                            'nns_hot_dgree'=>isset($val_playbill['key_val_list']['HotDgree']) ? $val_playbill['key_val_list']['HotDgree'] : 0,
                            'nns_cp_id'=>$message['nns_cp_id'],
                            'nns_import_source'=>isset($val_playbill['nns_import_source']) ? $val_playbill['nns_import_source'] : evn::get("project"),
                            'nns_ext_url'=>'',
                            'nns_image_v'=>isset($val_playbill['key_val_list']['verticality_img']) ? $val_playbill['key_val_list']['verticality_img'] : '',
                            'nns_image_h'=>isset($val_playbill['key_val_list']['horizontal_img']) ? $val_playbill['key_val_list']['horizontal_img'] : '',
                            'nns_image_s'=>isset($val_playbill['key_val_list']['square_img']) ? $val_playbill['key_val_list']['square_img'] : '',
                        ), //基本信息（存储于nns_live表中）
                        'hide_info' => array(
                            'nns_id' => np_guid_rand(),
                            'nns_state' => isset($val_playbill['key_val_list']['State']) ? $val_playbill['key_val_list']['State'] : 1,
                            'nns_deleted' => 0,
                            'nns_check' => isset($val_playbill['key_val_list']['Check']) ? $val_playbill['key_val_list']['Check'] : 1,
                        )
                    );
                    //字段待修改4-14
                    $result = $this->live_action('add', $add_playbill);
                }
                if($result['ret'] != 0)
                {
                    break;
                }
            }
        }

        //栏目注入走透传
        if (!empty($arr_category))
        {
            foreach ($arr_category as $val_category)
            {
                $action = $val_category['Action'] == 'DELETE' ? 2 : 1;
                $result = $this->add_category_pass($val_category, $action);
                if($result['ret'] !=0)
                {
                    $this->create_xml_respond_msg_to_csp($result['ret'], $result['reason']);
                    return $result;
                }
            }

        }

    }

    /**
     * 处理帕科透传添加媒资包栏目
     * @param $content
     * @param $action
     * @return array|bool
     */
    private function add_category_pass($content,$action)
    {
        if (isset($this->assists_arr["{$content['ParentID']}"]) && strlen($this->assists_arr["{$content['ParentID']}"]) > 0)
        {
            $content['ParentID'] = $this->assists_arr["{$content['ParentID']}"];
        }

        if($action == 1)
        {
            $category_info[] = array(
                'category_id' => $content['ContentID'],
                'parent_category' => $content['key_val_list']['ParentID'],
                'name' => $content['key_val_list']['Name'],
            );
        }
        elseif($action == 2)
        {
            $category_info[] = $content['ContentID'];
        }
        else
        {
            \m_config::write_message_execute_log("操作类型错误请求action：" . var_export($action, true), $this->str_cp_id);
            return false;
        }

        $json_data = json_encode($category_info);
        //组装pass_queue需要的参数
        $add_pass_queue = array(
            "base_info" => array(
                "nns_action" => $action,
                "nns_type" => 0,
                "nns_message_id" => $this->msg_id,
                "nns_cp_id" => $this->str_cp_id,
                "nns_status" => 1,
                "nns_content" => $json_data,
            )
        );
        $re = $this->pass_queue_action('add', $add_pass_queue);
        \m_config::write_message_execute_log("加入到透传队列结果" . var_export($re, true), $this->str_cp_id);
        return $re;
    }

    /**
     * 消息队列注入播控统一反馈给上级，组装消息结构
     * @param int $state
     * @param string $reason
     */
    public function create_xml_respond_msg_to_csp($state = 0, $reason='')
    {
        if ($state == 0)
        {
            \m_config::write_callback_log('不是最终成功状态不进行反馈', 'zhongguangchuanbo', $this->msg_id);
            return;
        }
        $site_url = $this->arr_cp_config['data_info']['nns_config']['site_callback_url'];
        \m_public::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '反馈到芒果二级地址信息：站点地址为-' . $site_url, $this->str_cp_id, $this->msg_id);
        //反馈状态转换

        if(!empty($site_url))
        {
            $params = array(
                'cmdResult' => $state === 0 ? 0 : -1,
                'type' => 1,
                'CSPID' => $this->str_cp_id,
                'LSPID' => 'starcor',
                'correlateID' => $this->msg_id,
                'ResultMsg' => $reason,
                'resultFileURL' => '',
            );
            $this->notify_msg($params,true,$site_url);
        }
        else
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '没有配置站点信息', $this->str_cp_id, $this->msg_id);
        }
    }

    /**
     * 进行消息反馈
     * @param $params
     * @param bool $bool
     * @param string $site_url
     * @return array|string
     */
    public function notify_msg($params, $bool=false, $site_url='')
    {
        $http_curl = new np_http_curl_class();
        $xml = $this->_build_notify_xml($params);
        \m_config::write_callback_log( '[' . date('Y-m-d H:i:s') . ']' . '反馈给上游的数据为：' . var_export($xml, true), $this->str_cp_id, $this->msg_id);

        if (!$bool)//是否异步反馈通知上游
        {
            return $xml;
        }
        if (!empty($site_url))
        {
            $xml = array('cmsResult'=> $xml);
            $http_header = array("Content-Type: application/x-www-form-urlencoded;charset=UTF-8");
            $response = $http_curl->post($site_url, http_build_query($xml), $http_header, 2);
            $curl_info = $http_curl->curl_getinfo();
            \m_config::write_callback_log( '[' . date('Y-m-d H:i:s') . ']' . '上游接收到反馈后响应的结果为：' . $response . ',POST反馈数据为：' . var_export($curl_info, true), $this->str_cp_id, $this->msg_id);
        } else
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '没有配置反馈地址', $this->str_cp_id, $this->msg_id);
        }
    }

    /**
     * @description:组装反馈的XML
     * @author:xinxin.deng
     * @date: 2018/2/26 14:25
     * @param $params
     * @return string|void
     */
    public function _build_notify_xml($params)
    {
        if(!is_array($params) || empty($params))
        {
            return ;
        }
        $dom = new DOMDocument('1.0', 'utf-8');
        $xmlresult = $dom->createElement('xmlresult');
        $dom->appendChild($xmlresult);
        foreach ($params as $key=>$value)
        {
            $$key = $dom->createElement($key);
            $xmlresult->appendchild($$key);
            if(!empty($value) && is_array($value))
            {
                foreach ($value as $k=>$val)
                {
                    $$k = $dom->createElement($k);
                    $$key->appendchild($$k);
                    //创建元素值
                    $content = $dom->createTextNode($val);
                    $$k->appendchild($content);
                }
            }
            else
            {
                //创建元素值
                $text = $dom->createTextNode($value);
                $$key->appendchild($text);
            }
        }
        return $dom->saveXML();
    }

    /**
     * @description:播控注入cdn后统一反馈给上游
     * @author:xinxin.deng
     * @date: 2018/3/2 9:59
     * @param $message_id //消息id
     * @param $code //状态码，失败1，成功0
     * @param $reason //原因描述
     * @param $arr_data //封装好了的反馈信息 array(
     *                                          'cdn_id' => ,注入cdn的id
     *                                          'site_id' => ,配置的站点id
     *                                          'mg_asset_type' => ,注入媒资类型
     *                                          'mg_asset_id' => ,主媒资的消息注入id
     *                                          'mg_part_id' => ,分集的消息注入id
     *                                          'mg_file_id' => ,片源的消息注入id,
     *                                          'is_finally' =>0, 0表示最终状态,反馈的时候将其unset掉
     *                                          );
     * @param $sp_id //sp_id
     */
    public function is_ok($message_id, $code, $reason, $arr_data, $sp_id)
    {
        $arr_sp_data = \m_config::_get_sp_info($sp_id);
        $sp_config = isset($arr_sp_data['data_info']['nns_config']) ? $arr_sp_data['data_info']['nns_config'] : array();

        //不是最终状态不进行反馈
        if (($code == 5 || $code == 98 || $code === 0) && (!isset($arr_data['is_finally']) || $arr_data['is_finally'] !== 0 || $arr_data['is_finally'] != null))
        {
            \m_config::write_callback_log('不是最终成功状态不进行反馈', DEFAULT_SOURCE_ID, $message_id);
            return;
        }
        unset($arr_data['is_finally']);
        $code = $code === 0 ? 0 : -1;
        $flag_message_feedback_enabled = (!isset($sp_config['message_feedback_enabled']) || $sp_config['message_feedback_enabled'] !=1) ? true : false;
        if(!$flag_message_feedback_enabled || !isset($sp_config['message_feedback_mode']) || $sp_config['message_feedback_mode'] != 0)
        {
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '不允许反馈或者反馈模式不正确：
            [message_feedback_enabled]=' . $sp_config['message_feedback_enabled'] . 'message_feedback_mode=' . $sp_config['message_feedback_mode'], DEFAULT_SOURCE_ID, $message_id);
            return;
        }

        //查询sp的上报地址/芒果使用站点ID
        if(isset($sp_config['site_callback_url']) && strlen($sp_config['site_callback_url']) > 0)
        {
            $xml_info = array(
                'cmdResult' => $code,
                'type' => 2,
                'CSPID' => DEFAULT_SOURCE_ID,
                'LSPID' => 'starcor',
                'correlateID' => $message_id,
                'ResultMsg' => $reason,
                'resultFileURL' => '',
            );

            $xml = self::_build_notify_xml($xml_info);
            \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '站点反馈地址为:' . var_export($sp_config['site_callback_url'], true) . ',反馈
            数据为:' . $xml, DEFAULT_SOURCE_ID, $message_id);

            $http_curl = new np_http_curl_class();
            for ($i = 0; $i < 3; $i++) {
		$xml = array('cmsResult'=> $xml);
                $http_header = array("Content-Type: application/x-www-form-urlencoded;charset=UTF-8");
                //访问媒资注入接口
                $re = $http_curl->post($sp_config['site_callback_url'], http_build_query($xml), $http_header, 2);
                $curl_info = $http_curl->curl_getinfo();
                $http_code = $curl_info['http_code'];
                \m_config::write_callback_log('[' . date('Y-m-d H:i:s') . ']' . '循环请求第' . $i . '次(如果请求返回post结果为true并且状态码不是200,就会默认循环3次,状态码为200,
                就跳出循环),' . '请求返回post结果为:' . $re . '请求返回状态为:' . var_export($http_code, true) . ',反回数据为:' . var_export($curl_info, true) . ',
                访问POST结果为:' . var_export($re, true), DEFAULT_SOURCE_ID, $message_id);

                if ($http_code != 200 && (int)$re === 1)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
        }
        return;
    }

    /**
     * @description:组装反馈的XML
     * @author:xinxin.deng
     * @date: 2018/2/26 14:25
     * @param $params
     * @return string|void
     */
    public function _build_notify_xml_v2($params)
    {
        if(!is_array($params) || empty($params))
        {
            return ;
        }
        $dom = new DOMDocument('1.0', 'utf-8');
        $xmlresult = $dom->createElement('xmlresult');
        $dom->appendChild($xmlresult);
        foreach ($params as $key=>$value)
        {
            $$key = $dom->createElement($key);
            $xmlresult->appendchild($$key);
            if(!empty($value) && is_array($value))
            {
                foreach ($value as $k=>$val)
                {
                    $$k = $dom->createElement($k);
                    $$key->appendchild($$k);
                    //创建元素值
                    $content = $dom->createTextNode($val);
                    $$k->appendchild($content);
                }
            }
            else
            {
                //创建元素值
                $text = $dom->createTextNode($value);
                $$key->appendchild($text);
            }
        }
        return $dom->saveXML();
    }

    private function handle_picture_v3($asset_id)
    {
        $array_img = array();
        $array_img['verticality_img']='';
        $array_img['horizontal_img']='';
        $array_img['bigpic']='';
        $array_img['middlepic']='';
        $array_img['smallpic']='';
        $array_img['square_img']='';
        if(empty($this->arr_picture) || !is_array($this->arr_picture))
        {
            return $array_img;
        }
        $array_map = $this->get_map_info_v2('Picture',$this->arr_map,$asset_id);
        if(empty($array_map))
        {
            return $array_img;
        }
        $array_map_key = array_keys($array_map);
        $temp_array = array();
        foreach ($this->arr_picture as $obj_picture)
        {
            if(!in_array($obj_picture['ContentID'], $array_map_key))
            {
                continue;
            }
            //组成数据,key为图片type,值为url
            if (!isset($obj_picture['key_val_list']['Type']))
            {
                foreach ($array_map as $k_id => $val)
                {
                    if ($obj_picture['ContentID'] == $k_id)
                    {
                        $obj_picture['key_val_list']['Type'] = $val['key_val_list']['Type'];
                    }
                }
            }
            $temp_array[$obj_picture['key_val_list']['Type']] = (isset($obj_picture['key_val_list']['FileURL']) && strlen($obj_picture['key_val_list']['FileURL']) >0) ? trim($obj_picture['key_val_list']['FileURL']) : '';
        }
        $temp_array = array_filter($temp_array);
        if(empty($temp_array))
        {
            return $array_img;
        }

        $arr_combine = $this->combine_picture($array_img, $temp_array);
        return array_combine(array_keys($array_img),$arr_combine);
    }

    private function get_map_info_v2($p_type,$arr_map, $e_id)
    {
        $temp_arr = array();
        if ($p_type == 'Picture')
        {
            foreach ($arr_map as $map)
            {
                if ($map['attributes']['ElementType'] == $p_type && $map['attributes']['ParentID'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ElementID']] = $filter_map;
                }
                if (isset($temp_arr[$map['attributes']['ElementID']]))
                {
                    continue;
                }
                if ($map['attributes']['ParentType'] == $p_type && $map['attributes']['ElementID'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ParentID']] = $filter_map;
                }
            }

        }
        else
        {
            foreach ($arr_map as $map)
            {
                if ($map['attributes']['ElementType'] == $p_type && $map['attributes']['ParentType'] != 'Picture' && $map['attributes']['ElementID'] == $e_id)
                {
                    $filter_map = $this->make_key_value_arr($map);
                    $temp_arr[$map['attributes']['ParentID']] = $filter_map;
                }
            }
        }
        return $temp_arr;
    }

    /**
     * 获取xml的 attr属性和key value值
     * @param unknown $xml_obj_arr
     * @return Ambigous <NULL, unknown, string>
     */
    private function make_key_value_arr($xml_obj_arr)
    {
        $key_val_array = null;
        if (isset($xml_obj_arr['attributes']) && is_array($xml_obj_arr['attributes']) && !empty($xml_obj_arr['attributes']))
        {
            foreach ($xml_obj_arr['attributes'] as $attr_key => $attr_val)
            {
                $key_val_array[$attr_key] = $attr_val;
            }
            if(!isset($key_val_array['ContentID']) || strlen($key_val_array['ContentID'])<1)
            {
                $key_val_array['ContentID'] = isset($xml_obj_arr['attributes']['ID']) ? $xml_obj_arr['attributes']['ID'] : '';
            }
            unset($xml_obj_arr['attributes']);
        }
        if (isset($xml_obj_arr['children']) && is_array($xml_obj_arr['children']) && !empty($xml_obj_arr['children']))
        {
            foreach ($xml_obj_arr['children'] as $key_list)
            {
                if (isset($key_list['attributes']['Name']) && strlen($key_list['attributes']['Name']) > 0)
                {
                    $key_val_array['key_val_list'][$key_list['attributes']['Name']] = (isset($key_list['content']) && strlen($key_list['content']) > 0) ? trim($key_list['content']) : '';
                }
            }
            unset($xml_obj_arr['children']);
        }
        return $key_val_array;
    }

    /**
     * 主媒资上下线
     * xinxin.deng 2018/9/4 14:45
     * @param array $content 内容
     * @param string $asset_id 主媒资ID
     * @param string $asset_type 类型
     * @return array
     */
    private function line_asset($content,$asset_id,$asset_type='video')
    {
        $order = 9999-(float)$content['order'];
        $line_asset_arr = array(
            'base_info' => array(
                'nns_message_id' => $this->msg_id,
                'nns_category_id' => $content['category_id'],
                'nns_order' => $order,
                'nns_action' => ($content['action'] == '5') ? 'unline' : 'online',
                'nns_cp_id' => $this->str_cp_id,
                'nns_import_id'  => $asset_id,
                'nns_type' => $asset_type,
                'nns_asset_id' => $content['asset_id'],
            )
        );
        \m_config::write_message_execute_log("封装上下线数据结果为：" . var_export($line_asset_arr, true), $this->str_cp_id);
        $re = $this->asset_online_action('add', $line_asset_arr);
        \m_config::write_message_execute_log("主媒资上下线,注入结果" . var_export($re, true), $this->str_cp_id);
        return $re;
    }

    /**
     * 合并图片类型
     * @param $arr_img
     * @param $arr_temp
     * @return array
     */
    private function combine_picture($arr_img, $arr_temp)
    {
        $arr_img = array_values($arr_img);
        foreach ($arr_temp as $k=> $item)
        {
            $arr_img[$k-1] = $item;
        }
        return $arr_img;
    }

    public function status($message_id)
    {

    }
}